package com.gws.ievent.service.job;

import com.alibaba.fastjson2.JSON;
import com.gws.ievent.common.Result;
import com.gws.ievent.common.utils.OkHttpUtil;
import com.gws.ievent.scheduler.Scheduler;
import lombok.Data;
import lombok.EqualsAndHashCode;


/**
 * @author song
 * @date 2022/10/22 21:11
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class HttpPostJob extends BaseJob {

    private final String url;
    private final Object body;

    public HttpPostJob(String url, Object body) {
        this.url = url;
        this.body = body;
    }

    /**
     * 执行方法
     *
     * @return
     */
    @Override
    protected Result<?> running(Scheduler event) {
        try {
            String s = OkHttpUtil.postJson(this.url, null, this.body);
            return JSON.parseObject(s, Result.class);
        } catch (Exception e) {
            return Result.fail(0, e.getMessage());
        }
    }

}
